package com.cium.aqie.branch

import com.cium.aqie.myClass.State

/**
 * @Function:
 * @Author: aqie
 * @Date: 2019/8/28 11:32
 */

fun main() {
    // println("user is ${ifTest()}")

    // switch 表达式
    // switchTest()

    val x = 5
    val num = "5"
    when(x){
        // 是否是整形
        is Int -> println("Hello $x")
        // 在不在区间中
        in 1..100 -> println("$x is in 1..100")
        !in 1..100 -> println("$x is not in 1..100")
        num.toInt() -> println("x == $num")
    }

    // when 也有返回值
    val mode = when{
        num.isNotEmpty() && num == "1" -> 1
        else -> 0
    }
    println(mode)
}

private fun switchTest() {
    var state = State.PLAYING

    when (state) {
        State.BUFFERING, State.PAUSED -> doPause()
        State.PLAYING -> doPlaying()
        else -> {
            doRun()
        }
    }
}

fun doPlaying() {
    println("playing")
}
fun doPause() {
    println("pause")
}

fun doRun() {
    println("run")
}

// if 表达式
private fun ifTest(): String {
    println("请输入用户名 ")
    val name = readLine()
    println("请输入密码")
    val passwd = readLine()


    var user = if (name == "aqie") {
        "aqie"
    } else {
        "cium"
    }
    return user
}




